﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Data;
using Luna.Data.Common;

namespace Luna.Data.Crm
{
    /// <summary>
    /// Mapper for data interface IEntityData.
    /// </summary>
    public partial class EntityDataMapper : LunaEntityMapper<EntityData, IEntityData> 
    {
        public EntityDataMapper()
        {
            GetAllRequest = DefaultGetAllRequest;
            GetRequest = DefaultGetRequest;
            InsertRequest = DefaultInsertRequest;
            UpdateRequest = DefaultUpdateRequest;
            DeleteRequest = DefaultDeleteRequest;
            
            Initialize();
        }
        
        partial void Initialize();
        
        private const string DefaultGetAllRequest = "Crm.entity_select_all";
        private const string DefaultGetRequest = "Crm.entity_select";
        private const string DefaultInsertRequest = "Crm.entity_insert";
        private const string DefaultUpdateRequest = "Crm.entity_update";
        private const string DefaultDeleteRequest = "Crm.entity_delete";
        
        private const string ManagerColumnName = "Manager";
        private const string SurnameColumnName = "Surname";
        private const string NameColumnName = "Name";
        private const string CompanyColumnName = "Company";
        private const string TitleColumnName = "Title";
        private const string PhoneColumnName = "Phone";
        private const string MobileColumnName = "Mobile";
        private const string SourceColumnName = "Source";
        private const string UrlColumnName = "Url";
        private const string MailColumnName = "Mail";
        private const string FaxColumnName = "Fax";
        private const string StatusColumnName = "Status";
        private const string SkypeColumnName = "Skype";
        private const string TwitterColumnName = "Twitter";
        private const string SectorColumnName = "Sector";
        private const string NoMailColumnName = "NoMail";
        private const string AddressColumnName = "Address";
        private const string ZipCodeColumnName = "ZipCode";
        private const string CityColumnName = "City";
        private const string CountryColumnName = "Country";
        private const string DescriptionColumnName = "Description";

        protected override void LoadCoreData(IEntityData entity, IDataRecord record)
        {
            entity.Manager = record.GetString(ManagerColumnName);
            entity.Surname = record.GetString(SurnameColumnName);
            entity.Name = record.GetString(NameColumnName);
            entity.Company = record.GetString(CompanyColumnName);
            entity.Title = record.GetString(TitleColumnName);
            entity.Phone = record.GetString(PhoneColumnName);
            entity.Mobile = record.GetString(MobileColumnName);
            entity.Source = record.GetString(SourceColumnName);
            entity.Url = record.GetString(UrlColumnName);
            entity.Mail = record.GetString(MailColumnName);
            entity.Fax = record.GetString(FaxColumnName);
            entity.Status = record.GetString(StatusColumnName);
            entity.Skype = record.GetString(SkypeColumnName);
            entity.Twitter = record.GetString(TwitterColumnName);
            entity.Sector = record.GetString(SectorColumnName);
            entity.NoMail = record.GetBoolean(NoMailColumnName);
            entity.Address = record.GetString(AddressColumnName);
            entity.ZipCode = record.GetString(ZipCodeColumnName);
            entity.City = record.GetString(CityColumnName);
            entity.Country = record.GetString(CountryColumnName);
            entity.Description = record.GetString(DescriptionColumnName);
        }
        
        protected override void MapSaveParameters(IDatabaseCommand command, IEntityData entity)
        {
            command.AddParameter(ManagerColumnName, entity.Manager);
            command.AddParameter(SurnameColumnName, entity.Surname);
            command.AddParameter(NameColumnName, entity.Name);
            command.AddParameter(CompanyColumnName, entity.Company);
            command.AddParameter(TitleColumnName, entity.Title);
            command.AddParameter(PhoneColumnName, entity.Phone);
            command.AddParameter(MobileColumnName, entity.Mobile);
            command.AddParameter(SourceColumnName, entity.Source);
            command.AddParameter(UrlColumnName, entity.Url);
            command.AddParameter(MailColumnName, entity.Mail);
            command.AddParameter(FaxColumnName, entity.Fax);
            command.AddParameter(StatusColumnName, entity.Status);
            command.AddParameter(SkypeColumnName, entity.Skype);
            command.AddParameter(TwitterColumnName, entity.Twitter);
            command.AddParameter(SectorColumnName, entity.Sector);
            command.AddParameter(NoMailColumnName, entity.NoMail);
            command.AddParameter(AddressColumnName, entity.Address);
            command.AddParameter(ZipCodeColumnName, entity.ZipCode);
            command.AddParameter(CityColumnName, entity.City);
            command.AddParameter(CountryColumnName, entity.Country);
            command.AddParameter(DescriptionColumnName, entity.Description);
            command.AddParameter(IDParameterName, entity.PK);
        }
    }
}